<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class Coupon extends NotORM {

    //设置表名
    protected function getTableName($id) {
        return 'coupon';
    }

    // 按获取区域
    public function getCoupon( $user_id ) {
        $time = time();
        $sql = 'SELECT cl.id, c.name, c.money, c.use_start_time, c.use_end_time, c.use_type, c.condition '
            . 'FROM tp_coupon AS c LEFT JOIN tp_coupon_list AS cl '
            . 'ON c.id = cl.cid '
            . 'WHERE cl.status = 0 AND c.use_start_time < '.$time.' AND c.use_end_time > '.$time.' AND cl.uid = '.$user_id
            . ' ORDER BY cl.send_time DESC';
        return $this->getORM()->queryAll($sql, array());
    }
}
